package com.haoshuang.zhouzhoubang.ui.activity

import android.os.Bundle
import com.haoshuang.zhouzhoubang.databinding.ActivityBindAlipayBinding
import com.haoshuang.zhouzhoubang.ui.vm.BindAlipayViewModel
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.state.observeState
import com.mufeng.libs.utils.toast
import com.mufeng.libs.utils.view.clickWithTrigger


/**
 *  绑定支付宝界面
 */
class BindAlipayActivity : BaseVMActivity<BindAlipayViewModel, ActivityBindAlipayBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        binding.apply {
            appBar.ivBack.clickWithTrigger { finish() }
            appBar.tvTitle.text = "绑定支付宝"
       }
    }

    override fun initData() {
        binding.btCommit.clickWithTrigger {
            var alipay_name=binding.alipayName.text.toString()
            var alipay_code=binding.alipayCode.text.toString()
            if (alipay_name.isNullOrBlank()){
                toast("输入支付宝昵称")
                return@clickWithTrigger
            }
            if (alipay_code.isNullOrBlank()){
                toast("输入支付宝账号")
                return@clickWithTrigger
            }
            vm.getData("alipay_name" to alipay_name,"alipay_code" to alipay_code)
        }
    }

    override fun startObserve() {
        vm.getData.observeState(this) {
                    onLoading { showLoading() }
                    onError { code, msg ->
                        dismissLoading()
                        toast(msg)
                    }
                    onSuccess {
                        dismissLoading()
                        toast("绑定成功")
                        finish()
                    }
                }
    }

}